vb 输入"我的妈妈来自中国的南方,我很爱她",判断有几个“我”

来源:百度知道 编辑:UC知道 时间:2024/05/09 14:16:50
编程 也可以是输入英语,里面有多少个字母或单词

Private Sub Command1_Click()
Dim Str1 As String, nStr As String, S As Long, G As Long

Str1 = InputBox("请输入要查找的字符:", "查找", "我")
If Str1 = "" Then Exit Sub
nStr = "我的妈妈来自中国的南方,我很爱她" '或:nStr=text1.text
Do
S = InStr(S + 1, nStr, Str1)
If S = 0 Then Exit Do
G = G + 1
Loop
MsgBox "找到 " & G & " 个字符:" & Str1, vbInformation
End Sub

Private Sub Command1_Click()
Dim Str1 As String, nStr As String, S As Long, G As Long

Str1 = InputBox("请输入要查找的字符:", "查找", "我")
If Str1 = "" Then Exit Sub
nStr = "我的妈妈来自中国的南方,我很爱她" '或:nStr=text1.text
Do
S = InStr(S + 1, nStr, Str1)
If S = 0 Then Exit Do
G = G + 1

啊哦,不明白